package GameLogic
{
	import BasicEngine.Dispatcher;
	import DataStore.BmpDataPool;
	import flash.display.Bitmap;
	import flash.display.Shape;
	import flash.display.Sprite;
	import flash.events.Event;
	import flash.text.TextField;
	import flash.utils.Dictionary;
	public class ShowTime extends Sprite
	{
		private var HourTxt:TextField;
		private var MinuteTxt:TextField;
		private var SecondTxt:TextField;
		private var MillisecondTxt:TextField;
		
		private var hour:int;
		private var minute:int;
		private var second:int;
		private var millisecond:int;
		
		public function ShowTime()
		{
			var dd:Dictionary = BmpDataPool.LuaeditPool;
			var img:Bitmap = new Bitmap(BmpDataPool.LuaeditPool[4020]);
			img.scaleX = img.scaleY = 0.5;
			img.y = 8;
			addChild(img);
			img.x = -27;
			var clr:int = 0xD0CECE;
			var s:Number = 2;
			HourTxt = new TextField();
			HourTxt.scaleX = HourTxt.scaleY = s;
			HourTxt.textColor = clr;
			HourTxt.selectable = false;
			HourTxt.width = 21;
			HourTxt.height = 22;
			var shape:Shape = new Shape();
			shape.graphics.beginFill(0x666666, 1);
			shape.graphics.lineStyle(1, 0x3E3A3A);
			shape.graphics.drawRect(0, 0, 13, 24);
			shape.graphics.drawRect(14, 0, 13, 24);
			shape.graphics.drawRect(35, 0, 13, 24);
			shape.graphics.drawRect(49, 0, 13, 24);
			shape.graphics.drawRect(70, 0, 13, 24);
			shape.graphics.drawRect(84, 0, 13, 24);
			shape.graphics.drawRect(105, 0, 13, 24);
			shape.graphics.drawRect(119, 0, 13, 24);
			shape.graphics.drawRect(133, 0, 13, 24);
			addChild(shape);
			shape.x = 3;
			shape.y = 5;
			
			MinuteTxt = new TextField();
			MinuteTxt.textColor = clr;
			MinuteTxt.scaleX = MinuteTxt.scaleY = s;
			MinuteTxt.selectable = false;
			MinuteTxt.width = 21;
			MinuteTxt.height = 22;
			
			SecondTxt = new TextField();
			SecondTxt.scaleX = SecondTxt.scaleY = s;
			SecondTxt.textColor = clr;
			SecondTxt.selectable = false;
			SecondTxt.width = 21;
			SecondTxt.height = 22;
			
			MillisecondTxt = new TextField();
			MillisecondTxt.scaleX = MillisecondTxt.scaleY = s;
			MillisecondTxt.textColor = clr;
			MillisecondTxt.selectable = false;
			MillisecondTxt.width = 26;
			MillisecondTxt.height = 22;
			
			addChild(HourTxt);
			addChild(MinuteTxt);
			addChild(SecondTxt);
			addChild(MillisecondTxt);
			var d:int = 35;
			MinuteTxt.x = d;
			SecondTxt.x = 2 * d;
			MillisecondTxt.x = 3 * d;		
			this.addEventListener(Event.ENTER_FRAME, function(e:Event):void
			{
				Update();
			});
			for (var i:int = 0; i < 3; i++)
			{
			   var colon:TextField = new TextField();
			   colon.text = ":";
			   colon.textColor = 0xffff00;
			   colon.scaleX = colon.scaleY = s;
			   colon.x = -7 + (i+1) * d;
			   addChild(colon);
			   colon.selectable = false;
			   colon.width = 21;
			   colon.height = 22;
			}
			
		}
		
		private function Update():void
		{
			if (!Game.Pause)
			{
				millisecond += Dispatcher.Clock.Tick;
				if (millisecond >= 1000)
				{
					second ++;
					millisecond = 0;
				}
				if (second >= 60)
				{
					minute++;
					second = 0;
				}
				if (minute >= 60)
				{
					hour++;
					minute = 0;
				}
			}
			if(hour > 9)
			   HourTxt.text = hour.toString();
			else
			   HourTxt.text = "0"+hour.toString();
			if(minute > 9)
			   MinuteTxt.text = minute.toString();
			else
			   MinuteTxt.text = "0"+minute.toString();
			if(second > 9)
			  SecondTxt.text = second.toString();
			else
			  SecondTxt.text = "0"+second.toString();
			MillisecondTxt.text = millisecond.toString();
			
		}
	}
}